// packageF/cps/order/order.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[],
    current_page: 1,
    last_page: 1,
    status:'',

    active: 0,
    language:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let language = wx.getStorageSync('langIndex');
    let json = {
      page:1
    }
    if(options.status !== 'undefined'){
      let _status =  Number(options.status);
      let status = '';
      let active1 = 0;
      if (_status == 4) {
        status = '';
      } else {
        status = _status
      }
      if (_status == 1) {
        active1 = 2
      } else if (_status == 0) {
        active1 = 1;
      } else if (_status == -1) {
        active1 = 3
      } else {
        active1 = status
      }      
      this.setData({active:active1})
      json.status = status;
    }
    this.setData({
      'language': language.en,
    });
    this.getData(json)
  },
  code_link(event) {
    wx.setClipboardData({
      data: event.currentTarget.dataset.orderid,
      success: () => {
        app.tips('复制成功')
      
      },
      fail: (err) => {
        app.tips('复制失败')
      }
    });
  },
  getData(json){
    app._getNetWork({
      url:app.getNetAddresss("plugin.tiktok-cps.api.order.order-list"),
      data:json,
      success:resdata=>{
        let {data,result,msg} = resdata.data;
        if(result == 0){
          return app.tips(msg);
        }
        if(json.page == 1){
          this.setData({list:data.list});
        }else{
          let list = this.data.list.concat(data.lsit);
          this.setData({list})
        }
        this.setData({current_page:data.current_page,last_page:data.last_page})
      }
    })
  },
  onChange(event) {
    let index = event.detail.index
    this.setData({
      active: index
    })
    console.log(index,'111',typeof index);
    let status = '';
    if(index == 0){
      status = ''
    }else if(index == 1){
      status = 0
    }else if(index == 2){
      status = 1
    }else {
      status = -1;
    }
    this.setData({status})
    this.getData({page:1,status})
  },
  getMoreData() {
    if (this.data.current_page >= this.data.last_page) {
      return false;
    }
    let page = Number(this.data.current_page) +1
    this.getData({page,status:this.data.status})

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})